{include file="public/header" /}
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>实物订单</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <form method="get">
        <div class="ds-search-form">
            <dl>
                <dt>{$Think.lang.order_number}</dt>
                <dd><input type="text" class="text w150" name="order_sn" value="{$Request.param.order_sn}"></dd>
            </dl>
            <dl>
                <dt>{$Think.lang.store_name}</dt>
                <dd><input type="text" class="text w150" name="store_name" value="{$Request.param.store_name}"></dd>
            </dl>
            <dl>
                <dt>{$Think.lang.order_state}</dt>
                <dd>
                    <select name="order_state" class="querySelect">
                        <option value="">{$Think.lang.ds_please_choose}</option>
                        <option value="10" {if condition="$Request.param.order_state eq '10'"}selected{/if}>{$Think.lang.order_state_new}</option>
                        <option value="20" {if condition="$Request.param.order_state eq '20'"}selected{/if}>{$Think.lang.order_state_pay}</option>
                        <option value="30" {if condition="$Request.param.order_state eq '30'"}selected{/if}>{$Think.lang.order_state_send}</option>
                        <option value="40" {if condition="$Request.param.order_state eq '40'"}selected{/if}>{$Think.lang.order_state_success}</option>
                        <option value="0" {if condition="$Request.param.order_state eq '0'"}selected{/if}>{$Think.lang.order_state_cancel}</option>
                    </select>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.order_time_from}</dt>
                <dd>
                    <input type="text" class="txt date" name="query_start_time" id="query_start_time" value="{$Request.param.query_start_time}">
                        &nbsp;–&nbsp;
                        <input id="query_end_time" class="txt date" type="text" name="query_end_time" value="{$Request.param.query_end_time}">
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.buyer_name}</dt>
                <dd>
                    <input type="text" class="text w80" name="buyer_name" value="{$Request.param.buyer_name}">
                </dd>
                <dd>
                    <select name="payment_code">
                        <option value="">{$Think.lang.ds_please_choose}</option>
                        {foreach $payment_list as $val} 
                        <option {if condition="$Request.param.payment_code eq $val.payment_code"}selected{/if} value="{$val.payment_code}">{$val.payment_name}</option>
                        {/foreach}
                    </select>
                </dd>
            </dl>
            <div class="btn_group">
                <input type="submit" class="btn" value="搜索">
                {if $filtered}
                <a href="{:url('Order/index')}" class="btn btn-default" title="{$Think.lang.ds_cancel}">{$Think.lang.ds_cancel}</a>
                {/if}
                <a class="btn btn-mini" href="javascript:export_xls('{:url('Order/export_step1')}')"><span>{$Think.lang.ds_export}Excel</span></a>
            </div>
        </div>    
    </form>

    <table class="ds-default-table">
        <thead>
            <tr>
                <th>{$Think.lang.order_number}</th>
                <th>{$Think.lang.store_name}</th>
                <th>{$Think.lang.buyer_name}</th>
                <th>{$Think.lang.order_time}</th>
                <th>{$Think.lang.order_total_price}</th>
                <th>{$Think.lang.payment}</th>
                <th>{$Think.lang.order_state}</th>
                <th>{$Think.lang.ds_handle}</th>
            </tr>
        </thead>
        {empty  name="order_list"}
        <tbody>
            <tr class="no_data">
                <td colspan="20">{$Think.lang.no_record}</td>
            </tr>
        </tbody>
        {else /}
        <tbody>
            {foreach name="order_list" item="order"}
            <tr>
                <td>{$order.order_sn}</td>
                <td>{$order.store_name}</td>
                <td>{$order.buyer_name}</td>
                <td>{$order.add_time|date="Y-m-d H:i:s",###}</td>
                <td>{$order.order_amount}</td>
                <td>{:get_order_payment_name($order['payment_code'])}</td>
                <td>{:get_order_state($order)}</td>
                <td>
                    <a href="javascript:dsLayerOpen('{:url('Order/show_order',['order_id'=>$order.order_id])}','查看实物订单-{$order.order_sn}')" class="dsui-btn-view"><i class="iconfont"></i>{$Think.lang.ds_view}</a>
                    {if condition="$order.if_cancel"}
                    <a href="javascript:dsLayerConfirm('{:url('Order/change_state',['state_type'=>'cancel','order_id'=>$order.order_id])}','{$Think.lang.order_confirm_cancel}')" class="dsui-btn-del"><i class="iconfont"></i>{$Think.lang.order_change_cancel}</a>
                    {/if}
                    {if condition="$order.if_system_receive_pay"}
                    <a href="javascript:dsLayerOpen('{:url('Order/change_state',['state_type'=>'receive_pay','order_id'=>$order.order_id])}','实物订单-{$order.order_sn}')" class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.order_change_received}</a>
                    {/if}
                   <!-- &lt;!&ndash;  同步管易【已支付,待发货才展示】，已同步的订单不展示“同步管易按钮”  &ndash;&gt;
                    {if condition="$order.order_state == 20 && $order.sync_to_border == 0"}
                        {if condition="in_array($order.order_id,$sucessOrderIds)"}
                            <a class="btn btn-mini" style="background-color: gray;margin-top:2px;">{$Think.lang.has_synced_to_erp}</a>
                        {else}
                            <a onclick="syncToGuanYi({$order.order_id})") class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.sync_to_erp}</a>
                        {/if}
                    {/if}
                    &lt;!&ndash;  已付款&待发货的订单，显示“同步物流”按钮  &ndash;&gt;
                    {if condition="$order.order_state == 20 && $order.shipping_code == ''"}
                    <a onclick="syncGuanYiDeliverToPlat({$order.order_id})") class="dsui-btn-edit" style="background-color: #208e24"><i class="iconfont"></i>{$Think.lang.erp_sync_to_plat}</a>
                    {/if}-->
                    <!--  跨境订单，同步前海【已支付&待同步&待发货才展示】，“同步前海按钮”  -->
                    {if condition="$order.order_state == 20 && $order.sync_to_border != 0"}

                    {if condition="$order.sync_to_border == 1"}
                    <a class="btn btn-mini" onclick="syncToQianHai({$order.order_id})")>{$Think.lang.sync_to_qianhai}</a>
                    {elseif condition="$order.sync_to_border == 2"}
                    <a class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.has_synced_to_qianhai}</a>
                    {else}
                    <a class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.has_failed_synced_to_qianhai}</a>
                    {/if}

                    {if condition="$order.send_to_haiguan == 1"}
                    <a class="btn btn-mini" onclick="syncToQianHai({$order.order_id})")>{$Think.lang.sync_to_haiguan}</a>
                    {elseif condition="$order.send_to_haiguan == 2"}
                    <a class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.has_synced_to_haiguan}</a>
                    {else}
                    <a class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.has_failed_synced_to_haiguan}</a>
                    {/if}



                    {/if}
                </td>
            </tr>
            {/foreach}
        </tbody>
        {/empty}
    </table>
    {$show_page}
</div>

<script type="text/javascript">
$(function(){
    $('#query_start_time').datepicker({dateFormat: 'yy-mm-dd'});
    $('#query_end_time').datepicker({dateFormat: 'yy-mm-dd'});
});
//同步管易物流信息 至 E驾优选平台
function syncGuanYiDeliverToPlat(order_id = 0) {
    $.post(
        "{:url('Order/syncGuanyiDeliverToPlat')}",
        {order_id:order_id},
        function (res) {
            resObj = jQuery.parseJSON(res);
            if(resObj.code != 10000)   layer.msg(resObj.message);

            layer.msg(resObj.message);
        }
    );
}
//同步管易
function syncToGuanYi(order_id = 0) {
    $.post(
        "{:url('Order/syncOrderToGuanYi')}",
        {order_id:order_id},
        function (res) {
            resObj = jQuery.parseJSON(res);
            if(resObj.code != 10000)   layer.msg(resObj.message);

            layer.msg(resObj.message);
        }
    );
}
//同步至前海
function syncToQianHai(order_id = 0) {
    $.post(
        "{:url('Order/syncOrderToQianHai')}",
        {order_id:order_id},
        function (res) {
            layer.msg(res.msg);
            location.reload();
        }
    );
}
//推送海关
function sendToHaiguan(order_id = 0) {
    $.post(
            "{:url('Order/sendToHaiguan')}",
            {order_id:order_id},
            function (res) {
                console.log(res);
//                layer.msg(res.msg);
//                location.reload();
            }
    );
}

</script> 

